package org.com.money.core;

import org.com.money.componet.BankCompment;
import org.com.money.componet.Msg;
import org.com.money.domain.User;
import org.com.money.service.MoneyException;

public class BankCompmentImpl implements BankCompment {

	@Override
	public User login(String id, String paswword) throws MoneyException {

		if (!id.equals(ID)) {
			throw new MoneyException(Msg.W004);
		} else if (!paswword.equals(PASSWORD)) {
			throw new MoneyException(Msg.W004);
		}
		
		
		
		final User user = new User();
		user.setAccount(ID);// 帳號
		user.setPassword(PASSWORD);// 密碼
		user.setTotalMoney(TOTAL_MONEY);// 總金額

		return user;
	}

	@Override
	public void getMoney(User user, int money) throws MoneyException {

		final int total = user.getTotalMoney();

		if (money > total) {
			throw new MoneyException(Msg.W002);
		} else {
			user.setTotalMoney(total - money);
		}

	}
}
